package com.glsc.ngateway.platform.aspect;

import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.Url;
import com.glsc.ngateway.platform.service.UrlService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Set;
import java.util.stream.Collectors;

@Component
public class AuthHelper {
    private static final Logger logger = LoggerFactory.getLogger(AuthHelper.class);

    private UrlService urlService;
    private Set<String> requireAuthUrlSet;


    public AuthHelper(UrlService urlService) {
        this.urlService = urlService;
//        this.requireAuthUrlSet = getAllRequireAuthUrls().stream()
//                .map(url -> url.getUrl())
//                .collect(Collectors.toSet());

    }

    public Set<Url> getAllRequireAuthUrls() {
        return urlService.queryAllByRequireAuth(1);
    }
    public Set<String> getAllRequireAuthUrlSet() {
        return urlService.queryAllUrlsByRequireAuth(1);
    }
    public boolean requireAuth(String url) {
        return getAllRequireAuthUrlSet().contains(url);
    }
}
